package group.Controller;


import group.Service.RabbitmqService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Ulegal on 2017/12/13.
 */

@RestController
public class RabbitmqController {


    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    RabbitmqService rabbitmqService;



         @GetMapping(value = "/rabbit")
         public String RabbitmqActivity(){

             rabbitmqService.RabbitmqActivity();

             return  "Rabbitmq";
         }

    @GetMapping(value = "/getRabbit")
    public String getRabbitmqActivity(){

//      String tt = (String) amqpTemplate.receiveAndConvert();
//设置回调，当消息成功发送到rabbitmq服务端时testConfirmCallback.confirm方法会被调用
//        rabbitTemplate.setConfirmCallback(testConfirmCallback);
        return  "Rabbitmq";
    }



    /**
     * 回调
     */
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        System.out.println(" 回调id:" + correlationData);
        if (ack) {
            System.out.println("消息成功消费");
        } else {
            System.out.println("消息消费失败:" + cause);
        }
    }


}





